package com.pruebas.andEngine;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.scene.background.SpriteBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

public class HowToPlay extends BaseGameActivity implements IOnSceneTouchListener {

	private static final int CAMERA_WIDTH = 800;
	private static final int CAMERA_HEIGHT = 480;

	private Camera mCamera;
	public Scene scene; 
	
	// IMAGEN COMO JUGAR
	private Texture mBackgroundTexture;
	private TextureRegion mBackgroundTextureRegion;
	
	// IMAGEN COMO JUGAR 2
	private Texture mBackgroundTexture2;
	private TextureRegion mBackgroundTextureRegion2;
	
	@Override
	public Engine onLoadEngine() {
		this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
	}

	@Override
	public void onLoadResources() {
		// en esta textura agrego la imagen de fondo
		this.mBackgroundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.mBackgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset((BitmapTextureAtlas) this.mBackgroundTexture, this, "gfx/howto_1.png", 0, 0);
		
		this.mBackgroundTexture2 = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.mBackgroundTextureRegion2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset((BitmapTextureAtlas) this.mBackgroundTexture2, this, "gfx/howto_2.png", 0, 0);

		// cargo la textura con la imagen de fondo
		this.mEngine.getTextureManager().loadTexture(this.mBackgroundTexture);
		this.mEngine.getTextureManager().loadTexture(this.mBackgroundTexture2);
	}

	@Override
	public Scene onLoadScene() {
		this.mEngine.registerUpdateHandler(new FPSLogger());
		//final Scene scene = new Scene();
		scene = new Scene();
		// aca agrego un sprite como background
		scene.setBackground(new SpriteBackground(new Sprite(0, 0, this.mBackgroundTextureRegion)));
		scene.setOnSceneTouchListener(this);
		return scene;
	}

	@Override
	public void onLoadComplete() {
	}

	@Override
	public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
		scene.setBackground(new SpriteBackground(new Sprite(0, 0, this.mBackgroundTextureRegion2)));
		return true;
	}
}
